package gui;

import java.awt.Color;
import java.awt.Rectangle;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

import constants.Constants;

public class ResultDialog extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JComboBox DateSelection = null;
	private JButton View = null;
	private JButton Cancel = null;
	JFrame fr;

	/**
	 * @param owner
	 */
	public ResultDialog(JFrame owner, Vector<String> data) {
		super(owner);
		initialize();
		fr = owner;
		populateList(data);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(400, 130);
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setBackground(new Color(250, 250, 250));
			jContentPane.setLayout(null);
			jContentPane.add(getDateSelection(), null);
			jContentPane.add(getView(), null);
			jContentPane.add(getCancel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes DateSelection
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getDateSelection() {
		if (DateSelection == null) {
			DateSelection = new JComboBox();
			DateSelection.setBackground(new Color(250, 250, 250));
			DateSelection.setBounds(new Rectangle(10, 10, 360, 25));
			return DateSelection;
		}
		return DateSelection;
	}

	/**
	 * This method initializes View
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getView() {
		if (View == null) {
			View = new JButton();
			View.setBounds(new Rectangle(110, 50, 120, 25));
			View.setText("View Graph");
			View.setFont(Constants.font);
			View.setForeground(Constants.blue);
			View.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JFrame frame = new JFrame(DateSelection.getSelectedItem()
							.toString());
					frame.setSize(725, 635);
					GraphPanel g = new GraphPanel(DateSelection
							.getSelectedItem().toString(), frame);
					frame.add(g);
					frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
					frame.setVisible(true);
				}
			});
		}
		return View;
	}

	/**
	 * This method initializes Cancel
	 * 
	 * @return javax.swing.JButton
	 */
	public void populateList(Vector<String> items) {
		DateSelection.removeAllItems();
		for (int i = 0; i < items.size(); i++) {
			DateSelection.addItem(items.get(i));
		}
	}

	private JButton getCancel() {
		if (Cancel == null) {
			Cancel = new JButton();
			Cancel.setBounds(new Rectangle(250, 50, 120, 25));
			Cancel.setText("Cancel");
			Cancel.setFont(Constants.font);
			Cancel.setForeground(Constants.blue);
			Cancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					setVisible(false);
				}
			});
		}
		return Cancel;
	}

} // @jve:decl-index=0:visual-constraint="10,10"
